#--coding:utf-8--
"""
自定义widget
"""
from django import newforms as forms
from django.utils.text import capfirst

class AdminSplitDateTime(forms.SplitDateTimeWidget):
    """
    A SplitDateTime Widget that has some admin-specific styling.
    """
    def __init__(self, attrs=None):
        widgets = [forms.TextInput(attrs={'class': 'vDateField', 'size': '10'}),
                   forms.TextInput(attrs={'class': 'vTimeField', 'size': '8'})]
        # Note that we're calling MultiWidget, not SplitDateTimeWidget, because
        # we want to define widgets.
        forms.MultiWidget.__init__(self, widgets, attrs)
        
    def decompress(self, value):
        if value:
            return [value.date(),value.time().strftime("%H:%M:%S")]
        return [None, None]
    
    def format_output(self, rendered_widgets):
        return u'''<p class="datetime">%s %s &nbsp;&nbsp;%s %s</p>''' % \
            (_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1])